import { Injectable } from "@nestjs/common";
import { Cron, CronExpression } from "@nestjs/schedule";
import { CharacterLocationService } from "./character-location.service";

@Injectable()
export class LocationCleanupService {
  constructor(private readonly locationService: CharacterLocationService) {}

  /**
   * 每5分钟清理一次离线玩家缓存
   */
  @Cron(CronExpression.EVERY_5_MINUTES)
  async cleanupOfflinePlayers() {
    try {
      await this.locationService.cleanupOfflinePlayers();
      console.log("✅ 离线玩家缓存清理完成");
    } catch (error) {
      console.error("❌ 离线玩家缓存清理失败:", error);
    }
  }
}
